﻿using System.Collections.Generic;

namespace AirportApp.Data
{
    public class CountriesByName : List<CountriesInGroup>
    {
        private static readonly string Groups = "#abcdefghijklmnopqrstuvwxyz";

        private Dictionary<string, CountriesInGroup> groups = new Dictionary<string, CountriesInGroup>();

        public CountriesByName(string[] allCountries)
        {
            if (allCountries == null)
            {
                return;
            }

            List<string> airport = new List<string>(allCountries);
            //people.Sort(Person.CompareByFirstName);
            Dictionary<string, CountriesInGroup> groups = new Dictionary<string, CountriesInGroup>();

            foreach (char c in Groups)
            {
                CountriesInGroup group = new CountriesInGroup(c.ToString());
                this.Add(group);
                groups[c.ToString()] = group;
            }

            foreach (string a in allCountries)
            {
                string key = a[0].ToString();
                key = key.ToLower();
                if (Groups.IndexOf(key) < 0)
                {
                    key = "#";
                }

                groups[key].Add(a);
            }
        }
    }
}
